import Vue from 'vue'

const has = Vue.directive('has', {
  inserted: function (el, binding, vnode) {
    if (!Vue.prototype.$HAS(binding.value)) {
      // 删除节点
      el.remove()
    }
  }
})

Vue.prototype.$HAS = function (value) {
  let isHas = false
  let buttonPermission = JSON.parse(localStorage.getItem('permission'))
  if (buttonPermission === undefined || buttonPermission === null) {
    return false
  }

  let targetArr = value.split(',')
  for (let i = 0; i < targetArr.length; i++) {
    // 只要含有其中一个就跳出循环
    if (buttonPermission.includes(targetArr[i])) {
      isHas = true
      break
    }
  }
  return isHas
}
export default has
